package com.harmontronics.hanma.paas.paas.domain.releasesetup.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.harmontronics.hanma.paas.paas.domain.releasesetup.entity.HmModelUpdateSql;
import com.harmontronics.hanma.paas.paas.domain.releasesetup.repository.persistence.HmModelUpdateSqlRepository;
import com.harmontronics.hanma.paas.paas.domain.releasesetup.repository.po.HmModelUpdateSqlPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service("hmModelUpdateSqlService")
@DS("#header.App-Unique")
public class HmModelUpdateSqlService {

    @Autowired
    private HmModelUpdateSqlRepository hmModelUpdateSqlRepository;


    public void save(HmModelUpdateSql hmModelUpdateSql) {
        HmModelUpdateSqlPO po = BeanUtil.toBean(hmModelUpdateSql, HmModelUpdateSqlPO.class);
        hmModelUpdateSqlRepository.save(po);
    }


    public void remove(List<String> ids) {
        hmModelUpdateSqlRepository.removeByIds(ids);
    }

    public List<HmModelUpdateSql> getList() {
        List<HmModelUpdateSqlPO> pos = hmModelUpdateSqlRepository.list();
        return Convert.toList(HmModelUpdateSql.class, pos);
    }

    public List<String> getSqls(String appUnique, Long sequence) {
        List<HmModelUpdateSqlPO> list = hmModelUpdateSqlRepository.getByAppUniqueAndSequence(appUnique, sequence);

        return list.stream().map(HmModelUpdateSqlPO::getModelSql).collect(Collectors.toList());
    }

}